package com.xb.system.mapper.db0;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xb.model.domain.DistinctUser;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

/**
 * (Users)表数据库访问层
 *
 * @author makejava
 * @since 2024-07-15 13:18:59
 */
@Mapper
public interface DistinctUserMapper extends BaseMapper<DistinctUser> {

    /**
     * 验证规则，手机号精确匹配，姓名互相包含匹配
     * @param phone
     * @param username
     * @return
     */
    @Select("SELECT COUNT(*) FROM distinct_user WHERE phone = #{phone} AND (name LIKE CONCAT('%', #{username}, '%') OR #{username} LIKE CONCAT('%', name, '%'))")
    int checkUserMatch(String phone, String username);

    @Select("CREATE INDEX idx_phone_name ON distinct_user (phone, name)")
    void createIndexes();

    @Select("DROP INDEX idx_phone_name ON distinct_user")
    void dropIndexes();
}

